// pages/cultureCoupons/platformCoupons/index.js
const common = require("../../../public.js");
Page({

  /**
   * 页面的初始数据
   */
  data: {
    couponId: '',
    adminCoupons: '',
    from: null,
    isLoading: false,
    type:'',
    flag:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options,"dsg")
    this.setData({
      couponId: options.dcId,
      from: options.from ? options.from : null,
      flag:options.flag ? options.flag : null,
    })
    this.getDetail()
  },
  getDetail() {
    const that = this
    const tempJson = {
      couponId: that.data.couponId
    }
    this.setData({
      isLoading: true
    })
    common.post('/discountCoupon/getAdminCouponById', tempJson, function (res) {
      if (res.status === 200) {
        that.setData({
          adminCoupons: res.data,
          type:res.data.type
        })
      } else {
        common.showRequestErrMsg(res)
      }
    }, function () {
      that.setData({
        isLoading: false
      })
    })
  },
  toStoreList() {
    wx.navigateTo({
      url: '/pages/cultureCoupons/useableStore/index?couponId=' + this.data.couponId + '&type=' + this.data.type,
    })
  },
  getCouponFinish() {
    this.getDetail()
  },

  onShareAppMessage: function (res) {
    if (res.from === 'button') {
      // 来自页面内转发按钮
      console.log(res.target)
      console.log(this.data.adminCoupons.id)
    }
    return {
      title: this.data.adminCoupons.name,
      imageUrl: 'http://feiyangimage.oss-cn-shanghai.aliyuncs.com/wxApplets/share.jpg',
      path: '/pages/cultureCoupons/platformCoupons/index?dcId=' + this.data.adminCoupons.id
    }
  },

  /**
  * 用户点击右上角分享
  */
//  onShareAppMessage: function () {
//   return {
//     title: '补贴来了，海量消费券，等你来抢！',
//     imageUrl: 'http://feiyangimage.oss-cn-shanghai.aliyuncs.com/wxApplets/share.jpg',
//     success: (res) => { },
//     fail: (res) => {
//       // 分享失败
//     }
//   }
// },
// onShareTimeline() {
//   const query = 'from=timeline&' + this.getJumpParma()
//   return {
//     title:'补贴来了，海量消费券，等你来抢！',
//     query
//   }
// },
})
